<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('后台管理')"/>
</head>
<body class="hold-transition skin-blue sidebar-mini layout-boxed">
<div class="wrapper">
    <th:block th:include="include :: headbar"/>
    <th:block th:include="include :: sidebar"/>
    <div class="content-wrapper">
        <section class="content-header">
            <h1>&nbsp;</h1>
            <ol class="breadcrumb">
                <li><a href="/index"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li><a href="#">商城管理</a></li>
                <li class="active">分类管理</li>
            </ol>
        </section>
        <section class="content">
            <div class="box box-solid">
                <form class="box-header with-border form-inline" id="form">
                    <input type="text" class="form-control input-sm" placeholder="名称" id="name" name="classifyName">
                    <button type="button" class="btn btn-success btn-sm btn-flat"
                            onclick="$.table.search('form',this.name)"><i
                            class="fa fa-search"></i> 搜索
                    </button>
                </form>
                <div class="box-body">
                    <div class="btn-group-sm form-inline" id="toolbar" classify="group">
                        <button type="button" class="btn btn-success btn-sm btn-flat" onclick="$.operate.add()"><i
                                class="fa fa-plus"></i> 添加
                        </button>
                        <button type="button" class="btn btn-primary btn-sm btn-flat" onclick="$.operate.edit()"><i
                                class="fa fa-edit"></i> 修改
                        </button>
                        <button type="button" class="btn btn-danger btn-sm btn-flat" onclick="$.operate.remove()"><i
                                class="fa fa-remove"></i> 删除
                        </button>
                    </div>
                    <table id="bootstrap-table" data-mobile-responsive="true"></table>
                </div>
            </div>
        </section>
    </div>
    <th:block th:include="include :: copyright"/>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = "/mall/classify";
    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + '/add',
            removeUrl: prefix + '/remove',
            updateUrl: prefix + '/edit/{id}',
            sortName: "sort",
            uniqueId: 'classifyId',
            modalName: "",
            modalWidth: 350,
            modalHeight: 260,
            columns: [
                {radio: true},
                {
                    title: "序号", formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                },
                {field: 'classifyName', title: '名称'},
                {field: 'modelCount', title: '车模数量'},
                {field: 'sort', title: '排序'},
                {field: 'createTime', title: '创建时间'},
                {title: '显示', align: 'center', formatter: statusFormatter}
            ]
        };
        $.table.init(options);

    });

    function statusFormatter(value, row, index) {
        if (row.status === "1") {
            return '<i class=\"fa fa-toggle-on text-info fa-lg\" onclick="disable(\'' + row.classifyId + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-off text-info fa-lg\" onclick="enable(\'' + row.classifyId + '\')"></i> ';
        }
    }

    function count(classifyId) {
        $.get(prefix + "/model/count?id=" + classifyId, function (resp) {
            modelCount = resp.data;
            $.table.refresh();
        });
    }


    function disable(classifyId) {
        $.post(prefix + "/changeStatus", {"classifyId": classifyId, "status": 0}, function (resp) {
            $.table.refresh();
        });
    }

    function enable(classifyId) {
        $.post(prefix + "/changeStatus", {"classifyId": classifyId, "status": 1}, function (resp) {
            $.table.refresh();
        });
    }
</script>
</body>
</html>
